﻿using System;
using System.Collections.Generic;

namespace Laurent_Data_Mudanca_Requisito_01
{
	public class LastWorkingDays
	{

		public List<DateTime> getLastDays( DateTime date, Int32 days, Boolean workingDays )
		{
			List<DateTime> _listDate = new List<DateTime>();
			List<DateTime> _listHoliday = null;
			Int32 _days = 0;

			loadListHoliday( ref _listHoliday );

			while( _days < days )
			{
				date = date.AddDays( -1 );

				if( workingDays )
				{
					if( date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday )
					{
						continue;
					}

					if( _listHoliday.Contains( date ) )
					{
						continue;
					}
				}

				_listDate.Add( date );
				_days++;
			}

			return _listDate;
		}

		private void loadListHoliday( ref List<DateTime> listHoliday )
		{
			listHoliday = new List<DateTime>();

			listHoliday.Add( new DateTime( 2012, 1, 1 ) );
			listHoliday.Add( new DateTime( 2012, 2, 21 ) );
			listHoliday.Add( new DateTime( 2012, 12, 25 ) );
			listHoliday.Add( new DateTime( 2012, 12, 31 ) );
		}

	}
}
